package cc.rengu.igas.share.core.service.asyncall;

import cc.rengu.oltp.service.base.DubboAsynBaseService;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.utility.annotation.BIZ_PROCESS;
import cc.rengu.oltp.utility.util.XmlTreeUtil;

import java.util.List;

/**
 * TODO 积分退款异步处理
 */
public class AsynScoreConsumeRefundService extends DubboAsynBaseService {
    @BIZ_PROCESS
    public void comboPaymentRevsal() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        OrderService orderService = new OrderServiceImpl();
        String sysNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.INST_ID);
        UserOrderInfo refundOrderInfo = (UserOrderInfo) xmlTreeUtil.getXmlTreeObjectValue("asynRefundOrderInfo", UserOrderInfo.class);
        PayOrderInfo scorePayOrderInfo = (PayOrderInfo) xmlTreeUtil.getXmlTreeObjectValue("asynPayOrderInfo", PayOrderInfo.class);
        List<MchntOrderInfo> mchntOrderInfoRefundList = xmlTreeUtil.getXmlTreeListObjectValue("asynMchntRefundOrderInfoList", MchntOrderInfo.class);
        /*判断退款结果，更新状态*/
//        Result<JNScoreConsumeRefundResponse> scoreResult = new Result<>();
//        ConvertUtil.convertOutput(scoreResult);
//        if(!scoreResult.isSuccess() || !OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode().equals(scoreResult.getResult().getRespCode())){
//            rglog.error("调用dubbo服务积分退款失败");
//
//            scorePayOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
//            scorePayOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
//            scorePayOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
//            if(!orderService.updateOrderInfo(null,null,scorePayOrderInfo)){
//                rglog.error("更新订单表状态失败");
//            }
//            return ;
//        }else {
//            JNScoreConsumeRefundResponse scoreConsumeResponse = scoreResult.getResult();
//            /*esb流水号*/
//            scorePayOrderInfo.setChannelReconKey(scoreConsumeResponse.getHeader().getTraceNo());
//            scorePayOrderInfo.setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
//            scorePayOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
//            scorePayOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
//
//            /*更新退款订单*/
//            if(!orderService.updateOrderInfo(null,null,scorePayOrderInfo)){
//                rglog.error("更新订单表状态失败");
//            }
//        }
        /*更新商户累计限额*/
    }
}
